<?php
// +---------------------------------------------------------------------
// | thinkcmf [ WE CAN DO IT MORE SIMPLE ]
// +---------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +---------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +---------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +---------------------------------------------------------------------
namespace cmf\behavior;

class ActionBeginBehavior 
{

    // 行为扩展的执行入口必须是run
    public function run(&$data)
    {
        $request = request();
        if($request->isPost()){
            $autoAlbumSave = $request->post('auto_album_save/a');
            if(!empty($autoAlbumSave)){
                foreach ($autoAlbumSave as $key=>$val){
                    $attrs = $request->post($val.'_attrs/a');
                    $result = [];
                    foreach ($attrs as $k=>$v){
                        $result[] = $v;
                    }
                    $request->post([$val=>json_encode($result)],'','');
                }
            }
        }
    }
}